using NetProtocol.POD;
using System.Collections.Generic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class MainCityNpcData
    {
        public int id;
        /// <summary>
        ///  配置id，应该不会重复
        /// </summary>
		public int cid;
        /// <summary>
        ///  是否激活
        /// </summary>
        public bool active;
        /// <summary>
        ///  当前坐标
        /// </summary>
        public Framework.Vector3Int pos;

        internal void Init(MainCityNpcPOD npcPOD)
        {
            id = npcPOD.id;
            cid = npcPOD.cid;
            active = npcPOD.active;
            pos = npcPOD.pos == null ? default : new Framework.Vector3Int((int)npcPOD.pos.x, (int)npcPOD.pos.y, (int)npcPOD.pos.z);
        }
    }

    public class MainCityRegionData
    {
        /// <summary>
        ///  区域cid
        /// </summary>
		public int cid;
        /// <summary>
        ///  天气cid
        /// </summary>
        public int weatherCid;
        /// <summary>
        ///  npc信息
        /// </summary>
        public Dictionary<int, MainCityNpcData> npcs;
    }

    public class MainCityData
    {
        public int curRegionCid;
        public Vector3 playerPos;
        public Dictionary<int, MainCityRegionData> regions;

        internal static MainCityData Create(MainCityPOD mainCityPOD)
        {
            var data = new MainCityData();
            data.Init(mainCityPOD);
            return data;
        }

        private void Init(MainCityPOD pod)
        {
            curRegionCid = pod.curRegionCid;
            var curPos = pod.curPos;
            playerPos = curPos == null ? default : new Vector3(curPos.x, curPos.y, curPos.z);
            regions = new();
            foreach (var regionPOD in pod.regions)
            {
                var regionData = new MainCityRegionData();
                regionData.cid = regionPOD.cid;
                regionData.weatherCid = regionPOD.weatherCid;
                regionData.npcs = new();
                foreach (var npcPOD in regionPOD.npcs)
                {
                    var npcData = new MainCityNpcData();
                    npcData.Init(npcPOD);
                    regionData.npcs.Add(npcData.id, npcData);
                }
                regions.Add(regionData.cid, regionData);
            }
        }
    }
}
